const thingService = require('../services/thingService')

const databridge = async ctx => {
  const data = ctx.request.body
  try {
    await thingService.databridge(data)
    ctx.status = 200
    ctx.body = {
      status: true,
      message: '获取桥接数据成功！'
    }
  } catch (error) {
    throw new HttpError(error.message, 400)
  }
}
const deviceStatus = async ctx => {
  const data = ctx.request.body
  try {
    await thingService.deviceStatus(data)
    ctx.status = 200
    ctx.body = {
      status: true,
      message: '获取设备连接状态成功！'
    }
  } catch (error) {
    throw new HttpError(error.message, 400)
  }
}

const temperature = async ctx => {
  const data = ctx.request.body
  try {
    await thingService.temperature(data)
    ctx.status = 200
    ctx.body = {
      status: true,
      message: '获取温度数据成功！'
    }
  } catch (error) {
    throw new HttpError(error.message, 400)
  }
}

module.exports = {
  databridge,
  deviceStatus,
  temperature
}
